//
//  ST_LikeMeItemView.swift
//  BTVideo
//
//  Created by DouLei on 2019/7/24.
//  Copyright © 2019 DouLei. All rights reserved.
//

import UIKit
import SwifterSwift
import SwiftyJSON
import SnapKit

class ST_LikeMeItemView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.addSubview(user_image_view)
        self.addSubview(username_mask_view)
        self.addSubview(username_label)
        
        user_image_view.snp.makeConstraints { (make) in
            make.edges.equalTo(self)
        }
        
        username_mask_view.snp.makeConstraints { (make) in
            make.left.right.bottom.equalTo(self)
            make.height.equalTo(40)
        }
        
        username_label.snp.makeConstraints { (make) in
            make.left.equalTo(self).offset(3)
            make.bottom.equalTo(self).offset(-2)
            make.right.equalTo(self).offset(-3)
        }
        self.cornerRadius = 5
        
        self.addSubview(icon_mask_view)
        icon_mask_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        
        addSubview(name_mask_view)
        name_mask_view.snp.makeConstraints { (make) in
            make.centerY.left.equalTo(username_label)
            make.right.equalToSuperview().offset(-23)
            make.height.equalTo(5)
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var json = JSON.null{
        didSet{
            
            self.username_label.text = json["nickname"].stringValue
            
            
            self.user_image_view.pin_setImage(from: json["avatar"].stringValue.compress_image().url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
//            icon_mask_view.isHidden = !BTExpiredMember()
            
            name_mask_view.isHidden = icon_mask_view.isHidden
        }
    }
    
//    MARK: -
    lazy var user_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        return control
    }()
    
    lazy var username_mask_view:UIImageView = {
        let control = UIImageView.init(image: ST_ImageUtils.imageName("消息_img_喜欢卡片蒙层")!)
        return control
    }()
    
    lazy var username_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.white
        control.font = UIFont.systemFont(ofSize: 10, weight: UIFont.Weight.regular)
        return control
    }()
    
    
    lazy var icon_mask_view:UIVisualEffectView = {

        let blurEffect = UIBlurEffect(style: .light)
        let control = UIVisualEffectView.init(effect: blurEffect)
        control.cornerRadius = 5
        return control
        
    }()
    
    lazy var name_mask_view:UIView = {
       let control = UIView()
        control.backgroundColor = Color.white
        control.alpha = 0.6
        control.cornerRadius = 4
        return control
    }()

}
